home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-07-13 | 56.8 KB | 1,940 lines |
- (*----------------------------------------------------------------------*)
- (* PibEditor --- Simple screen editor for PibTerm *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE PibEditor;
-
- VAR
- EditFileName : AnyStr;
-
- (*----------------------------------------------------------------------*)
- (* Editor --- Main program for screen editor for PibTerm *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Editor( EditFileName : AnyStr );
-
- CONST
- MaxLines = 7000 (* Maximum lines allowed here *);
- MaxECol = 80 (* Maximum length line to edit *);
-
- TYPE (* Only lines up to 80 chars can be edited *)
- TextLine = STRING[MaxECol];
- (* Points to text lines being edited *)
- LinePtr = ^TextLine;
- (* Pointers to text lines *)
-
- LineBufferType = ARRAY[1..MaxLines] OF LinePtr;
- LineBufferTypePtr = ^LineBufferType;
-
- VAR
- KeyNum : INTEGER (* Key entered as editor command input *);
- CurrentLine : INTEGER (* Current Line being edited in file *);
- Column : INTEGER (* Current column in Line being edited *);
- I : INTEGER (* General purpose index *);
- HighestLine : INTEGER (* Last Line in file being edited *);
- ScreenLine : INTEGER (* Current Line on screen *);
- ScreenCol : INTEGER (* Current column on screen *);
- Page_Size : INTEGER (* Maximum # of lines per screen *);
- InKey : CHAR (* Keyboard entry *);
- SecInKey : CHAR (* Second character of escape sequence *);
- Choice : CHAR (* Selected option character *);
- Ch : CHAR (* General purpose character *);
- IntMaxLines : INTEGER (* Integer maximum lines available *);
- FirstColumn : INTEGER (* First column displayed *);
- LastColumn : INTEGER (* Last column displayed *);
-
- (* Array of pointers to text lines *)
-
- LineBuffer : LineBufferTypePtr;
-
- (* Pointer to empty Line *)
- EmptyLine : LinePtr;
- (* Marks tab stop columns *)
-
- TabSet : ARRAY[1..MaxECol] OF BOOLEAN;
-
- (* File to be read/written, if any *)
- TextFile : Text_File;
-
- SearchString : AnyStr (* String to search for *);
- Replacement : AnyStr (* String to replace selected string *);
-
- SecNum : BOOLEAN (* TRUE if escape sequence entered *);
- InsertMode : BOOLEAN (* TRUE if Insert mode active *);
- Edit_Done : BOOLEAN (* TRUE if editing session complete *);
-
- Local_Save : Saved_Screen_Ptr (* Saves screen image *);
- Main_Save : Saved_Screen_Ptr (* Saves screen image *);
-
- (*----------------------------------------------------------------------*)
- (* Quick_Display --- display Line by writing to screen memory *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Quick_Display( X , Y: INTEGER; S: AnyStr );
-
- VAR
- L: INTEGER;
-
- BEGIN (* Quick_Display *)
-
- IF ( ORD(S[0]) > MaxECol ) THEN
- S[0] := CHR(MaxECol);
-
- WriteSXY( S, X, Y + 1, Global_Text_Attribute );
-
- L := X + ORD(S[0]);
-
- IF ( L <= Max_Screen_Col ) THEN
- BEGIN
- GoToXY( L , Y );
- ClrEol;
- END;
-
- END (* Quick_Display *);
-
- (*----------------------------------------------------------------------*)
- (* DrawScreen --- Display text lines on screen *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE DrawScreen;
-
- VAR
- I: INTEGER;
- L: INTEGER;
-
- BEGIN (* DrawScreen *)
-
- FOR I := 1 TO Page_Size DO
- BEGIN
- L := CurrentLine - ScreenLine + I;
- IF ( ( L <= HighestLine ) AND ( L > 0 ) ) THEN
- Quick_Display( 1, I, LineBuffer^[ L ]^ )
- ELSE
- BEGIN
- GoToXY( 1 , I );
- ClrEol;
- END;
- END;
-
- END (* DrawScreen *);
-
- (*----------------------------------------------------------------------*)
- (* Edit_Press_Any --- display message and wait for key to be pressed *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Edit_Press_Any( S: AnyStr );
-
- BEGIN (* Edit_Press_Any *)
-
- WRITE( S );
-
- Read_Kbd( Ch );
-
- IF ( ( ORD( Ch ) = ESC ) AND KeyPressed ) THEN
- READ( Kbd, Ch );
-
- END (* Edit_Press_Any *);
-
- (*----------------------------------------------------------------------*)
- (* NewBuffer --- Allocate memory for new text line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE NewBuffer( VAR Buf: LinePtr );
-
- BEGIN (* NewBuffer *)
-
- NEW( Buf );
-
- END (* NewBuffer *);
-
- (*----------------------------------------------------------------------*)
- (* ZapBuffer --- Deallocate memory for text line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE ZapBuffer( VAR Buf: LinePtr );
-
- BEGIN (* ZapBuffer *)
-
- IF( Buf <> EmptyLine ) THEN
- BEGIN
- DISPOSE( Buf );
- Buf := EmptyLine;
- END;
-
- END (* ZapBuffer *);
-
- (*----------------------------------------------------------------------*)
- (* ReadFile --- Read existing text file into memory *)
- (*----------------------------------------------------------------------*)
-
- FUNCTION ReadFile( Name: AnyStr ) : BOOLEAN;
-
- VAR
- Trunc_Lines : INTEGER;
- S : AnyStr;
- L : INTEGER;
-
- BEGIN (* ReadFile *)
- (* Bring up read window *)
-
- Save_Partial_Screen( Local_Save, 5, 10, 75, 16 );
-
- Draw_Menu_Frame( 5, 10, 75, 16, Menu_Frame_Color, Menu_Title_Color,
- Menu_Text_Color, 'Read file ' + Name );
-
- (* See if text file exists *)
- (*$I-*)
- ASSIGN( TextFile, Name );
- RESET ( TextFile );
- (*$I+*)
-
- IF ( Int24Result <> 0 ) THEN
- BEGIN
- WRITELN( CHR( BELL ) );
- WRITELN(' File not found');
- ReadFile := TRUE;
- Edit_Press_Any( ' Press any key to continue ... ');
- Restore_Screen( Local_Save );
- Reset_Global_Colors;
- EXIT;
- END;
-
- GoToXY( 1 , 1 );
- WRITE(' Reading Line ');
- ClrEol;
- (* Keep track of truncated lines *)
- Trunc_Lines := 0;
-
- REPEAT
- (* Read line from input file *)
- READLN( TextFile, S );
- (* Increment line count *)
-
- CurrentLine := SUCC( CurrentLine );
-
- IF ( ( CurrentLine MOD 25 ) = 0 ) THEN
- BEGIN
- GoToXY( 15 , WhereY );
- WRITE( CurrentLine );
- END;
- (* Allocate line if necessary *)
-
- IF ( LineBuffer^[CurrentLine] = EmptyLine ) THEN
- NewBuffer( LineBuffer^[CurrentLine] );
-
- (* Truncate line to MaxECol characters *)
- L := ORD( S[0] );
-
- IF ( L > MaxECol ) THEN
- BEGIN
- Trunc_Lines := SUCC( Trunc_Lines );
- L := MaxECol;
- END;
- (* Move input text to line buffer *)
-
- MOVE( S[1] , LineBuffer^[CurrentLine]^[1] , L );
- LineBuffer^[CurrentLine]^[0] := CHR( L );
-
-
- IF ( CurrentLine > IntMaxLines ) THEN
- BEGIN
- WRITELN;
- WRITELN(' File is too long to edit with PibTerm editor.');
- WRITELN(' Only ',IntMaxLines,' lines allowed.');
- Edit_Press_Any( ' Press any key to continue ... ');
- ReadFile := FALSE;
- Restore_Screen( Local_Save );
- Reset_Global_Colors;
- EXIT;
- END;
-
- UNTIL ( EOF( TextFile ) );
-
- (*$I-*)
- CLOSE( TextFile );
- (*$I+*)
-
- IF ( Trunc_Lines > 0 ) THEN
- BEGIN
- WRITELN;
- WRITELN(' ', Trunc_Lines, ' lines longer than ',MaxECol:1,' characters ',
- 'truncated to ',MaxECol:1,' characters.');
- Edit_Press_Any( ' Press any key to continue ... ');
- END;
-
- ReadFile := TRUE;
-
- Restore_Screen( Local_Save );
- Reset_Global_Colors;
-
- END (* ReadFile *);
-
- (*----------------------------------------------------------------------*)
- (* LoadFile --- Prepare to edit file *)
- (*----------------------------------------------------------------------*)
-
- FUNCTION LoadFile( Name: AnyStr ) : BOOLEAN;
-
- BEGIN (* LoadFile *)
- (* No lines in file yet. *)
- CurrentLine := 0;
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
- Clear_Window;
-
- IF ( Name <> '' ) THEN
- LoadFile := ReadFile( Name )
- ELSE
- LoadFile := TRUE;
-
- HighestLine := CurrentLine;
- CurrentLine := 1;
- Column := 1;
- ScreenLine := 1;
-
- DrawScreen;
-
- END (* LoadFile *);
-
- (*----------------------------------------------------------------------*)
- (* DispKey --- Display a function key definition *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE DispKey( S: AnyStr );
-
- BEGIN (* DispKey *)
-
- TextColor( Menu_Text_Color );
-
- WRITE( S[1] );
-
- TextColor( LightGray );
-
- WRITE( COPY( S, 2, 80 ) );
-
- END (* DispKey *);
-
- (*----------------------------------------------------------------------*)
- (* DisplayKeys --- Display function key definitions *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE DisplayKeys;
-
- BEGIN (* DisplayKeys *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- DispKey('1Help ');
- DispKey('2Locate ');
- DispKey('3Search ');
- DispKey('4Replace ');
- DispKey('5SaveQuit ');
- DispKey('6InsLine ');
- DispKey('7DelLine ');
- DispKey('0QuitNosave ');
-
- TextColor( ForeGround_Color );
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
-
- END (* DisplayKeys *);
-
- (*----------------------------------------------------------------------*)
- (* Initialize --- Initialize editor *)
- (*----------------------------------------------------------------------*)
-
- FUNCTION Initialize( Name : AnyStr ) : BOOLEAN;
-
- VAR
- Drive: CHAR;
- Path : AnyStr;
- FileN: AnyStr;
- FileT: AnyStr;
- BadF : BOOLEAN;
-
- BEGIN (* Initialize *)
- (* Get # lines to display per screen *)
-
- Set_Screen_Size( Max_Screen_Line , Max_Screen_Col );
-
- Page_Size := Max_Screen_Line - 3;
-
- (* Clear screen *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- Clear_Window;
- (* Start out in selected insert mode *)
-
- InsertMode := Edit_Insert_Mode;
-
- (* Initialize status Line *)
- TextColor( Menu_Frame_Color );
-
- GoToXY( 1 , 1 );
- WRITE( Dupl( CHR( 205 ) , Max_Screen_Col ) );
-
- TextColor( Menu_Text_Color );
- GoToXY( 1 , 1 );
-
- IF InsertMode THEN
- WRITE( 'Insert ' )
- ELSE
- WRITE( 'Replace' );
-
- TextColor( Menu_Frame_Color );
- WRITE( CHR( 205 ) );
-
- GoToXY(1,24);
- WRITE( Dupl( CHR( 196 ) , Max_Screen_Col ) );
-
- TextColor( Menu_Text_Color );
- GoToXY(12,1);
- WRITE(' PibTerm Editor ');
-
- IF ( LENGTH( EditFileName ) > 0 ) THEN
- BEGIN
-
- Split_File_Name( EditFileName, Drive, Path, FileN, FileT, BadF );
-
- GoToXY(31,1);
-
- WRITE(' ',FileN, '.',FileT,' ')
-
- END;
- (* Display function key definitions *)
- DisplayKeys;
-
- TextColor( ForeGround_Color );
- (* Start at top of file *)
- CurrentLine := 1;
- Column := 1;
- ScreenLine := 1;
- HighestLine := 1;
-
- EmptyLine^ := '';
- SearchString := '';
- Replacement := '';
- (* Set up tab stops at usual PC places *)
- FOR I := 1 TO MaxECol DO
- TabSet[I] := ( ( I MOD 8 ) = 1 );
-
- (* General purpose empty line *)
- NewBuffer( EmptyLine );
- (* Figure # of lines fitting in our space *)
-
- IntMaxLines := MIN( MaxLines , TRUNC( ( MaxBlockAvail - 4096.0 ) / 100.0 ) );
-
- IF ( IntMaxLines <= 1 ) THEN
- BEGIN
- WRITELN;
- Edit_Press_Any(' There isn''t enough memory to do any editing.');
- Initialize := FALSE;
- END
- ELSE
- BEGIN
- (* Get space for line pointers *)
-
- GETMEM( LineBuffer , SIZEOF( LinePtr ) * IntMaxLines );
-
- (* Initialize line pointers to empty *)
-
- FOR I := 1 TO IntMaxLines DO
- LineBuffer^[I] := EmptyLine;
-
- GoToXY( 10 , 20 );
- (* Read in file to be edited, if any *)
-
- Initialize := LoadFile( Name );
-
- END;
-
- END (* Initialize *);
-
- (*----------------------------------------------------------------------*)
- (* Help --- provide help screen *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Help;
-
- CONST
- MaxHelpPage = 2;
-
- VAR
- Ch : CHAR;
- HPage : INTEGER;
- Help_Done : BOOLEAN;
-
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Help1;
-
- BEGIN (* Help1 *)
-
- Quick_Display( 5, 3, 'Character left ^S Left arrow');
- Quick_Display( 5, 4, 'Character right ^D Right arrow');
- Quick_Display( 5, 5, 'Word left ^A Ctrl left arrow');
- Quick_Display( 5, 6, 'Word right ^F Ctrl right arrow');
- Quick_Display( 5, 7, 'Left end of line ^Q Home');
- Quick_Display( 5, 8, 'Right end of line ^R End');
- Quick_Display( 5, 9, 'Line up ^E Up arrow');
- Quick_Display( 5, 10, 'Line down ^X Down arrow');
- Quick_Display( 5, 11, 'Page up ^W PgUp');
- Quick_Display( 5, 12, 'Page down ^Z PgDn');
- Quick_Display( 5, 13, 'Top of file ^O Ctrl PgUp');
- Quick_Display( 5, 14, 'Bottom of file ^L Ctrl PgDn');
-
- Quick_Display( 5, 16, 'Insert mode on/off ^V Ins');
- Quick_Display( 5, 17, 'Delete char at cursor ^G Del');
- Quick_Display( 5, 18, 'Delete left character ^H BackSpace');
-
- Quick_Display( 5, 20, 'Control char prefix ^P');
-
- END (* Help1 *);
-
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Help2;
-
- BEGIN (* Help2 *)
-
- Quick_Display( 5, 3, 'Display help ^K1 F1');
- Quick_Display( 5, 4, 'Locate string ^K2 F2');
- Quick_Display( 5, 5, 'Search for a string ^K3 F3');
- Quick_Display( 5, 6, 'Search and replace ^K4 F4');
- Quick_Display( 5, 7, 'Save file and quit ^K5 F5');
- Quick_Display( 5, 8, 'Insert blank line ^K6 F6');
- Quick_Display( 5, 9, 'Delete line ^K7 F7');
- Quick_Display( 5, 10, 'Quit without saving ^K0 F10');
-
- END (* Help2 *);
-
- (*----------------------------------------------------------------------*)
-
- BEGIN (* Help *)
- (* Help page one *)
- HPage := 1;
- (* Help not done yet *)
- Help_Done := FALSE;
- (* Loop over help pages *)
- REPEAT
- (* Set window size *)
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
-
- (* Clear edit screen *)
- Clear_Window;
- (* Display help text *)
-
- Quick_Display( 15, 1, 'PibTerm Editor Help, page ' + IToS( HPage ) );
-
- CASE HPage OF
- 1: Help1;
- 2: Help2;
- ELSE ;
- END (* CASE *);
-
- Window( 1 , 1 , Max_Screen_Col , Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
- (* Wait for key to be pressed *)
-
- WRITE('Hit ESC to return to editing or Enter for next help screen');
-
- Read_Kbd( Ch );
-
- IF ( Ch <> CHR( ESC ) ) THEN
- BEGIN
- HPage := SUCC( HPage );
- IF ( HPage > MaxHelpPage ) THEN
- HPage := 1;
- END
- ELSE
- Help_Done := TRUE;
-
- UNTIL ( Help_Done );
- (* Redisplay function keys and *)
- (* redraw screen display *)
- DisplayKeys;
- DrawScreen;
-
- END (* Help *);
-
- (*----------------------------------------------------------------------*)
- (* PrintRow --- Update status Line with new row/column *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE PrintRow;
-
- BEGIN (* PrintRow *)
- (* Display revised Line *)
-
- Window( 1 , 1 , Max_Screen_Col , Max_Screen_Line );
-
- TextColor( Menu_Text_Color );
-
- GoToXY( 54 , 1 );
- WRITE(' Line ', CurrentLine : 4,' ');
-
- (* Display revised row *)
- GoToXY( 68 , 1 );
- WRITE(' Col ', Column : 2,' ');
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
-
- TextColor( ForeGround_Color );
-
- END (* PrintRow *);
-
- (*----------------------------------------------------------------------*)
- (* GetKey --- Read keyboard input *)
- (*----------------------------------------------------------------------*)
-
- FUNCTION GetKey( VAR SecNum: BOOLEAN;
- VAR InKey: CHAR ): BOOLEAN;
-
- (* STRUCTURED *) CONST
- Digits : SET OF '0'..'9' = ['0'..'9'];
-
- BEGIN (* GetKey *)
-
- IF KeyPressed THEN
- BEGIN
-
- READ( Kbd , InKey);
- SecNum := ( InKey = CHR( ESC ) ) AND KeyPressed;
-
- IF SecNum THEN
- BEGIN
- READ( Kbd , Ch );
- KeyNum := ORD( Ch ) + 128;
- END
- ELSE
- IF ( ORD( InKey ) <= ESC ) THEN
- BEGIN
- SecNum := TRUE;
- KeyNum := ORD(InKey);
- IF ( InKey = ^K ) THEN
- BEGIN
- Read_Kbd( Ch );
- IF ( Ch IN Digits ) THEN
- IF ( Ch <> '0' ) THEN
- KeyNum := F1 + ORD( Ch ) - ORD( '0' ) + 128
- ELSE
- KeyNum := F10 + 128
- ELSE
- Menu_Beep;
- END
- ELSE IF ( InKey = ^P ) THEN
- BEGIN
- Read_Kbd( Ch );
- SecNum := FALSE;
- KeyNum := ORD( InKey );
- END;
- END
- ELSE
- BEGIN
- KeyNum := ORD(InKey);
- SecNum := FALSE;
- END
- END
- ELSE
- BEGIN
- GetKey := FALSE;
- SecNum := FALSE;
- END;
-
- END (* GetKey *);
-
- (*----------------------------------------------------------------------*)
- (* Character --- Insert Character at current pos in Line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Character;
-
- BEGIN (* Character *)
- (* See if room to Insert a character *)
-
- IF ( Column = PRED( MaxECol ) ) THEN
-
- Menu_Beep (* No room -- sound bell *)
- ELSE
- BEGIN
- (* Room -- display character at current *)
- (* screen position *)
-
- GoToXY( Column , ScreenLine );
- WRITE( InKey );
- (* Update line buffer pointer and text *)
- (* line itself. *)
-
- IF ( LineBuffer^[CurrentLine] = EmptyLine ) THEN
- BEGIN
- NewBuffer(LineBuffer^[CurrentLine]);
- LineBuffer^[CurrentLine]^ := '';
- END;
- (* Append any blanks needed *)
-
- WHILE ( LENGTH(LineBuffer^[CurrentLine]^) < Column ) DO
- LineBuffer^[CurrentLine]^ := LineBuffer^[CurrentLine]^ + ' ';
-
- (* Insert character in Line *)
-
- Insert(InKey, LineBuffer^[CurrentLine]^, Column);
-
- (* Update column positions *)
- Column := SUCC( Column );
- (* If not insert mode, delete character *)
-
- IF ( NOT InsertMode ) THEN
- Delete(LineBuffer^[CurrentLine]^, Column, 1);
-
- (* Redraw current Line if Insert mode active *)
- IF InsertMode THEN
- Quick_Display( 1 , ScreenLine , LineBuffer^[CurrentLine]^ );
-
- (* Ring bell when close to end of a Line *)
- IF ( Column = 70 ) THEN
- Menu_Beep;
-
- END;
-
- END (* Character *);
-
- (*----------------------------------------------------------------------*)
- (* BeginFile --- Move to top of file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE BeginFile;
-
- BEGIN (* BeginFile *)
- (* Reset Line pointers to top of file *)
- CurrentLine := 1;
- Column := 1;
- ScreenLine := 1;
-
- FirstColumn := 1;
- LastColumn := 80;
- (* Display lines at top of file *)
- DrawScreen;
-
- END (* BeginFile *);
-
- (*----------------------------------------------------------------------*)
- (* EndFile --- Move to end of file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE EndFile;
-
- BEGIN (* EndFile *)
- (* Reset Line pointers to end of file *)
-
- CurrentLine := HighestLine;
- ScreenLine := MIN( HighestLine , 12 );
- Column := 1;
- (* Display lines at end of file *)
- DrawScreen;
-
- END (* EndFile *);
-
- (*----------------------------------------------------------------------*)
- (* FuncEnd --- Move to end of current Line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE FuncEnd;
-
- BEGIN (* FuncEnd *)
-
- Column := MIN( LENGTH( LineBuffer^[CurrentLine]^ ) + 1 , MaxECol );
-
- END (* FuncEnd *);
-
- (*----------------------------------------------------------------------*)
- (* CursorUp --- Move up one Line in file/screen *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE CursorUp;
-
- VAR
- Count: INTEGER;
-
- BEGIN (* CursorUp *)
- (* Do nothing if already at top of file *)
- IF ( CurrentLine <= 1 ) THEN
- EXIT;
- (* Move back one Line in file; if at top *)
- (* line on screen, perform scroll down *)
-
- CurrentLine := PRED( CurrentLine );
-
- IF ( ScreenLine = 1 ) THEN
- BEGIN
- GoToXY( 1 , 1 );
- InsLine;
- Quick_Display( 1, 1, LineBuffer^[CurrentLine]^ );
- END
- ELSE
- ScreenLine := PRED( ScreenLine );
-
- END (* CursorUp *);
-
- (*----------------------------------------------------------------------*)
- (* CursorDown --- Move down one Line in file/screen *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE CursorDown;
-
- BEGIN (* CursorDown *)
- (* Down arrow doesn't move past EOF *)
-
- IF ( CurrentLine >= HighestLine ) THEN EXIT;
-
- (* Increment Line counter *)
-
- CurrentLine := SUCC( CurrentLine );
-
- (* Increment screen Line counter *)
-
- ScreenLine := SUCC( ScreenLine );
-
- (* If at last Line on screen, perform *)
- (* scroll up. *)
-
- IF ( ScreenLine > Page_Size ) THEN
- BEGIN
- GoToXY(1, 1);
- DelLine;
- ScreenLine := Page_Size;
- Quick_Display( 1 , ScreenLine , LineBuffer^[CurrentLine]^ );
- END;
-
- END (* CursorDown *);
-
- (*----------------------------------------------------------------------*)
- (* InsertLine --- Insert one Line in file/screen *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE InsertLine;
-
- BEGIN (* InsertLine *)
- (* Insert Line on screen *)
- InsLine;
- (* Move Line pointers up a slot *)
-
- FOR I := SUCC( HighestLine ) DOWNTO CurrentLine DO
- LineBuffer^[SUCC(I)] := LineBuffer^[I];
-
- (* Make new Line empty *)
-
- LineBuffer^[CurrentLine] := EmptyLine;
-
- (* Increment Line count *)
-
- HighestLine := SUCC( HighestLine );
-
- END (* InsertLine *);
-
- (*----------------------------------------------------------------------*)
- (* Enter --- handle enter key pressed *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Enter;
-
- VAR
- LTemp : AnyStr;
- RTemp : AnyStr;
- L : INTEGER;
-
- BEGIN (* Enter *)
- (* If insert mode active, split line *)
- (* at current column position. *)
- IF InsertMode THEN
- BEGIN
- (* Get characters up to marked column *)
-
- LTemp := Substr( LineBuffer^[CurrentLine]^, 1, PRED( Column ) );
-
- L := LENGTH( LineBuffer^[CurrentLine]^ );
-
- (* Get remaining characters -- these *)
- (* form the next line. *)
-
- RTemp := Substr( LineBuffer^[CurrentLine]^, Column, L - Column + 1 );
-
- (* Update first Line *)
-
- LineBuffer^[CurrentLine]^ := LTemp;
-
- (* Make room for new Line *)
- { CursorDown; }
- (* Increment Line counter *)
-
- CurrentLine := SUCC( CurrentLine );
-
- (* Increment screen Line counter *)
-
- ScreenLine := SUCC( ScreenLine );
-
- (* If at last Line on screen, perform *)
- (* scroll up. *)
-
- IF ( ScreenLine > Page_Size ) THEN
- BEGIN
- GoToXY( 1 , 1 );
- DelLine;
- ScreenLine := Page_Size;
- Quick_Display( 1 , ScreenLine , LineBuffer^[CurrentLine]^ );
- END;
-
- InsertLine;
- (* Allocate space for new Line *)
-
- NewBuffer(LineBuffer^[CurrentLine]);
-
- (* New Line is second half of old Line *)
-
- LineBuffer^[CurrentLine]^ := RTemp;
-
- (* Display revised lines *)
- DrawScreen;
-
- END
- ELSE (* If replace mode, move to next Line *)
- CursorDown;
-
- Column := 1;
- GoToXY( Column , ScreenLine );
-
- END (* Enter *);
-
- (*----------------------------------------------------------------------*)
- (* DeleteLine --- Delete a Line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE DeleteLine;
-
- BEGIN (* DeleteLine *)
- (* If no current lines, do nothing. *)
-
- IF ( HighestLine = 0 ) THEN EXIT;
-
- (* Delete current line on screen *)
- DelLine;
- (* Move up lines below it to fill in *)
-
- IF ( HighestLine > CurrentLine + ( Page_Size + 1 - ScreenLine ) ) THEN
- Quick_Display( 1 , Page_Size ,
- LineBuffer^[ CurrentLine + ( Page_Size + 1 - ScreenLine ) ]^ );
-
- (* Make this line empty *)
-
- ZapBuffer( LineBuffer^[CurrentLine] );
-
- (* Move down higher line pointers *)
-
- FOR I := CurrentLine TO HighestLine DO
- LineBuffer^[I] := LineBuffer^[SUCC(I)];
-
- (* Empty out former last line in file *)
-
- ZapBuffer( LineBuffer^[HighestLine] );
-
- (* Drop Line count *)
-
- HighestLine := PRED( HighestLine );
-
- (* Reset current line if > new last line *)
-
- IF ( CurrentLine > HighestLine ) THEN
- CursorUp;
-
- END (* DeleteLine *);
-
- (*----------------------------------------------------------------------*)
- (* CursorLeft --- Move one column to left *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE CursorLeft;
-
- BEGIN (* CursorLeft *)
- (* Move one column to left *)
- Column := PRED( Column );
- (* Move to previous Line if ran off *)
- (* left end of current line. *)
- IF ( Column < 1 ) THEN
- BEGIN
- CursorUp;
- FuncEnd;
- END;
-
- END (* CursorLeft *);
-
- (*----------------------------------------------------------------------*)
- (* CursorRight --- Move one column to right *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE CursorRight;
-
- BEGIN (* CursorRight *)
- (* Move forward one column *)
- Column := SUCC( Column );
- (* Move to next Line if needed *)
-
- IF ( Column > PRED( MaxECol ) ) THEN
- BEGIN
- CursorDown;
- Column := 1;
- END;
-
- END (* CursorRight *);
-
- (*----------------------------------------------------------------------*)
- (* Ins --- Toggle insert/overwrite mode *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Ins;
-
- BEGIN (* Ins *)
- (* Flip insert/overwrite mode *)
-
- InsertMode := ( NOT InsertMode );
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , 1 );
- (* Update status display *)
- TextColor( Menu_Text_Color );
-
- IF InsertMode THEN
- BEGIN
- WRITE( 'Insert ' );
- TextColor( Menu_Frame_Color );
- WRITE( CHR( 205 ) );
- END
- ELSE
- WRITE('Replace');
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
-
- TextColor( ForeGround_Color );
-
- END (* Ins *);
-
- (*----------------------------------------------------------------------*)
- (* Del --- Delete a character *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Del;
-
- BEGIN (* Del *)
- (* Join following Line to current Line *)
- (* if delete past end of Line *)
-
- IF ( Column > LENGTH(LineBuffer^[CurrentLine]^) ) THEN
- BEGIN
- IF ( ( LENGTH(LineBuffer^[CurrentLine]^ ) +
- LENGTH(LineBuffer^[CurrentLine+1]^ ) ) < MaxECol ) THEN
- BEGIN
-
- LineBuffer^[CurrentLine]^ := LineBuffer^[CurrentLine]^ +
- LineBuffer^[CurrentLine+1]^;
-
- Quick_Display( 1, ScreenLine, LineBuffer^[CurrentLine]^ );
- CursorDown;
- DeleteLine;
- CursorUp;
- DrawScreen;
- END
- ELSE
- WRITE( CHR( BELL ) );
- EXIT;
- END;
- (* Line already empty *)
-
- IF ( LineBuffer^[CurrentLine] = EmptyLine ) THEN
- BEGIN
- NewBuffer(LineBuffer^[CurrentLine]);
- LineBuffer^[CurrentLine]^ := '';
- END;
- (* Append blanks as needed *)
-
- WHILE ( LENGTH(LineBuffer^[CurrentLine]^) < Column ) DO
- LineBuffer^[CurrentLine]^ := LineBuffer^[CurrentLine]^ + ' ';
-
- (* Delete character from text Line *)
-
- Ch := COPY( LineBuffer^[CurrentLine]^, Column, 1 );
- DELETE( LineBuffer^[CurrentLine]^, Column, 1 );
-
- (* Redisplay updated Line *)
- GoToXY(1,ScreenLine);
- ClrEol;
-
- Quick_Display( 1 , ScreenLine , LineBuffer^[CurrentLine]^ );
-
- END (* Del *);
-
- (*----------------------------------------------------------------------*)
- (* BackSpace --- Move left and possibly delete character *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE BackSpace;
-
- BEGIN (* BackSpace *)
- (* Move one column to left *)
- Column := PRED( Column );
- (* Move to previous Line if ran off *)
- (* left end of current line. *)
- IF ( Column < 1 ) THEN
- BEGIN
- CursorUp;
- FuncEnd;
- END;
- (* Delete character *)
- Del;
-
- END (* BackSpace *);
-
- (*----------------------------------------------------------------------*)
- (* Terminate --- End editing session *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Terminate;
-
- VAR
- HoldName : AnyStr;
- Dot_Pos : INTEGER;
- F : FILE;
- I : INTEGER;
-
- BEGIN (* Terminate *)
- (* Remove status lines *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1, Max_Screen_Line );
- ClrEol;
- GoToXY( 1, PRED( Max_Screen_Line ) );
- ClrEol;
- (* Bring up write window *)
-
- Save_Partial_Screen( Local_Save, 5, 10, 75, 15 );
-
- Draw_Menu_Frame( 5, 10, 75, 15, Menu_Frame_Color, Menu_Title_Color,
- Menu_Text_Color, 'Write file ' );
-
- (* Pick up file name if none given *)
- IF ( EditFileName = '' ) THEN
- BEGIN
- WRITELN(' Enter file name to write to: ');
- WRITE(' >');
- Read_Edited_String( EditFileName );
- WRITELN;
- END
- ELSE
- (* Get .BAK form of name *)
- BEGIN
-
- HoldName := EditFileName;
-
- Dot_Pos := POS( '.' , HoldName );
-
- IF ( Dot_Pos = 0 ) THEN
- HoldName := HoldName + '.BAK'
- ELSE
- HoldName := COPY( HoldName, 1, Dot_Pos ) + 'BAK';
-
- (* Erase any previous .BAK file *)
- (*$I-*)
- ASSIGN( F , HoldName );
- RESET ( F );
- (*$I+*)
-
- IF ( INT24Result = 0 ) THEN
- BEGIN
- CLOSE( F );
- ERASE( F );
- END;
- (* Rename old version as *.BAK *)
- (*$I-*)
- RENAME( TextFile , HoldName );
- (*$I+*)
- I := INT24RESULT;
-
- END;
- (* Write the edited version *)
- WRITE(' Writing Line ');
- ClrEol;
-
- ASSIGN ( TextFile , EditFileName );
- REWRITE( TextFile );
-
- FOR I := 1 TO HighestLine DO
- BEGIN
-
- IF ( ( I MOD 25 ) = 0 ) THEN
- BEGIN
- GoToXY( 15 , WhereY );
- WRITE( I );
- END;
-
- WRITELN(TextFile, LineBuffer^[I]^);
-
- END;
-
- GoToXY( 15 , WhereY );
- WRITE( I );
- WRITELN;
-
- (*$I-*)
- CLOSE ( TextFile );
- (*$I+*)
-
- Edit_Press_Any(' File written. Press any key to exit ...');
-
- (* Editing done *)
- Edit_Done := TRUE;
-
- Restore_Screen( Local_Save );
- Reset_Global_Colors;
-
- END;
-
- (*----------------------------------------------------------------------*)
- (* QuitNoSave --- End editor session without saving file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE QuitNoSave;
-
- BEGIN (* QuitNoSave *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1, Max_Screen_Line );
- ClrEol;
-
- GoToXY( 1, PRED( Max_Screen_Line ) );
- ClrEol;
-
- Edit_Done := TRUE;
-
- END (* QuitNoSave *);
-
- (*----------------------------------------------------------------------*)
- (* FuncPgUp --- move up one screenful in file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE FuncPgUp;
-
- BEGIN (* FuncPgUp *)
- (* Back up one screen in file *)
-
- CurrentLine := CurrentLine - Page_Size;
-
- (* If backed up past start of file, *)
- (* display start of file. *)
-
- IF ( CurrentLine <= ScreenLine ) THEN
- BeginFile
- ELSE
- DrawScreen;
-
- END (* FuncPgUp *);
-
- (*----------------------------------------------------------------------*)
- (* FuncPgDn --- move down one screenful in file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE FuncPgDn;
-
- BEGIN (* FuncPgDn *)
- (* Move forward one page in file *)
-
- CurrentLine := CurrentLine + Page_Size;
-
- (* If past end of file, display *)
- (* end of file. *)
-
- IF ( ( CurrentLine + 12 ) >= HighestLine ) THEN
- EndFile
- ELSE
- DrawScreen;
-
- END (* FuncPgDn *);
-
- (*----------------------------------------------------------------------*)
- (* PrevWord --- move left one word in file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE PrevWord;
-
- BEGIN (* PrevWord *)
-
- (* If in word move to space *)
-
- WHILE ( NOT ( ( LineBuffer^[CurrentLine]^[Column] = ' ' ) OR
- ( Column >= LENGTH(LineBuffer^[CurrentLine]^) ) ) ) AND
- ( ( CurrentLine <> 1 ) OR ( Column <> 1 ) ) DO
- CursorLeft;
-
- (* Find end of previous word *)
-
- WHILE ( ( LineBuffer^[CurrentLine]^[Column] = ' ' ) OR
- ( Column >= LENGTH(LineBuffer^[CurrentLine]^) ) ) AND
- ( ( CurrentLine <> 1 ) OR ( Column <> 1 ) ) DO
- CursorLeft;
- (* Find start of previous word *)
-
- WHILE ( NOT ( ( LineBuffer^[CurrentLine]^[Column] = ' ' ) OR
- ( Column >= LENGTH(LineBuffer^[CurrentLine]^) ) ) ) AND
- ( ( CurrentLine <> 1 ) OR ( Column <> 1 ) ) DO
- CursorLeft;
-
- (* Position to start of previous word *)
- CursorRight;
-
- END (* PrevWord *);
-
- (*----------------------------------------------------------------------*)
- (* NextWord --- Move forward in Line one word *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE NextWord;
-
- BEGIN (* NextWord *)
-
- (* If in word, move to the whitespace *)
-
- WHILE ( NOT ( ( LineBuffer^[CurrentLine]^[Column] = ' ' ) OR
- ( Column >= LENGTH( LineBuffer^[CurrentLine]^ ) ) ) ) AND
- ( CurrentLine < HighestLine ) DO
- CursorRight;
-
- (* Skip over space to next word *)
-
- WHILE ( ( LineBuffer^[CurrentLine]^[Column] = ' ' ) OR
- ( Column >= LENGTH(LineBuffer^[CurrentLine]^) ) ) AND
- ( CurrentLine < HighestLine ) DO
- CursorRight;
-
- END (* NextWord *);
-
- (*----------------------------------------------------------------------*)
- (* Tab --- Move forwards in Line one tab stop *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Tab;
-
- BEGIN (* Tab *)
-
- IF ( Column < PRED( MaxECol ) ) THEN
- REPEAT
- Column := Column + 1;
- UNTIL ( TabSet[Column] ) OR ( Column = PRED( MaxECol ) );
-
- END (* Tab *);
-
- (*----------------------------------------------------------------------*)
- (* BackTab --- Move backwards in Line one tab stop *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE BackTab;
-
- BEGIN (* BackTab *)
-
- IF ( Column > 1 ) THEN
- REPEAT
- Column := PRED( Column );
- UNTIL ( TabSet[Column] ) OR ( Column <= 1 );
-
- END (* BackTab *);
-
- (*----------------------------------------------------------------------*)
- (* Esc --- Handle escape key (clear current line) *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Esc_Key;
-
- BEGIN (* Esc_Key *)
- (* Move to column one of current Line *)
- Column := 1;
- GoToXY(1, WhereY);
- (* Clear it *)
- ClrEol;
- (* Make it empty *)
-
- ZapBuffer( LineBuffer^[CurrentLine] );
-
- END (* Esc_Key *);
-
- (*----------------------------------------------------------------------*)
- (* Locate --- Locate all lines containing string *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Locate;
-
- VAR
- Temp : AnyStr;
- Pointer : INTEGER;
- Position : INTEGER;
- Line : INTEGER;
- Len : INTEGER;
-
- BEGIN (* Locate *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1, Max_Screen_Line );
- ClrEol;
-
- WRITE('Locate: Enter string> ');
-
- Read_Edited_String( SearchString );
-
- Len := LENGTH( SearchString );
-
- IF ( Len = 0 ) THEN
- BEGIN
- DisplayKeys;
- BeginFile;
- EXIT;
- END;
-
- GoToXY(1, 25);
- ClrEol;
- WRITE('Searching... Press <ESC> to exit, <SCROLL LCK> to pause');
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
- Clear_Window;
-
- FOR I := 1 TO HighestLine DO
- BEGIN
- (* look for matches on this Line *)
-
- Pointer := POS( SearchString, LineBuffer^[I]^ );
-
- (* If there was a match then get *)
- (* ready to display it *)
- IF ( Pointer > 0 ) THEN
- BEGIN
- Temp := LineBuffer^[I]^;
- Position := Pointer;
- GoToXY( 1 , WhereY );
- TextColor( LightGray );
- WRITE( COPY( Temp, 1, PRED( MaxECol ) ) );
-
- (* Honor scroll lock *)
-
- WHILE( Scroll_Lock_On ) DO;
-
- (* print all of the matches on this Line *)
-
- WHILE ( Pointer > 0 ) DO
- BEGIN
- GoToXY(Position, WhereY);
- WRITE( COPY( Temp, Pointer, Len ) );
- Temp := COPY( Temp, Pointer + Len + 1, 128);
- Pointer := POS( SearchString, Temp);
- Position := Position + Pointer + Len;
- END;
- (* go to next Line and keep searching *)
- WRITELN;
-
- END;
-
- END;
-
- TextColor( ForeGround_Color );
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- Edit_Press_Any('End of Locate. Press any key to exit ...');
-
- (* Display function keys *)
- DisplayKeys;
- (* Return to top of file *)
- BeginFile;
-
- END (* Locate *);
-
- (*----------------------------------------------------------------------*)
- (* Search --- Search for string in text *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Search;
-
- VAR
- Temp : AnyStr;
- Pointer : INTEGER;
- Position : INTEGER;
- Line : INTEGER;
- Len : INTEGER;
-
- BEGIN (* Search *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- WRITE('Search: Enter string> ');
-
- Read_Edited_String( SearchString );
-
- Len := LENGTH( SearchString );
-
- IF ( Len = 0 ) THEN
- BEGIN
- DisplayKeys;
- BeginFile;
- EXIT;
- END;
-
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- WRITE('Searching...');
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
-
- FOR I := ( CurrentLine + 1 ) TO HighestLine DO
- BEGIN
- (* look FOR matches on this Line *)
-
- Pointer := POS( SearchString, LineBuffer^[I]^);
-
- (* IF there was a match THEN get *)
- (* ready to print it *)
- IF ( Pointer > 0 ) THEN
- BEGIN
- CurrentLine := I;
- IF CurrentLine >= 12 THEN
- ScreenLine := 12
- ELSE
- ScreenLine := CurrentLine;
-
- DrawScreen;
- Column := Pointer;
-
- TextColor( LightGray );
-
- GoToXY(Column,ScreenLine);
- WRITE(SearchString);
-
- TextColor( ForeGround_Color );
-
- DisplayKeys;
-
- EXIT;
-
- END;
-
- END;
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- Edit_Press_Any('Search string not found. Press any key to exit ...');
-
- DisplayKeys;
-
- END (* Search *);
-
- (*----------------------------------------------------------------------*)
- (* Replace --- Search for and replace string in text *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Replace;
-
- VAR
- Temp : AnyStr;
- Position : INTEGER;
- Line : INTEGER;
- Len : INTEGER;
- S_Len : INTEGER;
- Save_Pos : INTEGER;
- L : INTEGER;
- IPos : INTEGER;
-
- BEGIN (* Replace *)
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- WRITE('Replace: Enter search string> ');
-
- Read_Edited_String(SearchString);
-
- S_Len := LENGTH(SearchString);
-
- IF ( S_Len = 0 ) THEN
- BEGIN
- DisplayKeys;
- EXIT;
- END;
-
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- WRITE('Replace: Enter replacement string> ');
-
- Read_Edited_String(Replacement);
-
- Len := LENGTH( Replacement );
-
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
- WRITE('Searching...');
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
- Clear_Window;
-
- Choice := ' ';
-
- FOR Line := CurrentLine TO HighestLine DO
- BEGIN
-
- Position := POS( SearchString, LineBuffer^[Line]^ );
-
- WHILE( Position > 0 ) DO
- BEGIN
-
- CurrentLine := Line;
-
- IF ( CurrentLine >= 12 ) THEN
- ScreenLine := 12
- ELSE
- ScreenLine := CurrentLine;
-
- DrawScreen;
- Column := Position;
-
- TextColor( LightGray );
-
- GoToXY(Column,ScreenLine);
- WRITE(SearchString);
-
- TextColor( ForeGround_Color );
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- IF ( Choice <> 'C' ) THEN
- BEGIN
- WRITE('Replace (Y/N/C/ESC)? ');
- Read_Kbd( Choice);
- Choice := UpCase( Choice );
- END;
-
- IF ( ORD( Choice ) = ESC ) THEN
- BEGIN
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
- GoToXY(Column,ScreenLine);
- WRITE(SearchString);
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- DisplayKeys;
- EXIT;
- END;
-
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- WRITE('Searching...');
-
- Window( 1, 2, Max_Screen_Col, SUCC( Page_Size ) );
- GoToXY( 1 , Line );
-
- IF Choice in ['C','Y'] THEN
- BEGIN
-
- L := LENGTH( LineBuffer^[Line]^ );
- IPos := Position + S_Len;
-
- LineBuffer^[Line]^ :=
- Substr( LineBuffer^[Line]^, 1, PRED( Position ) ) +
- Replacement +
- Substr( LineBuffer^[Line]^, IPos, L - IPos + 1 );
-
- L := LENGTH( LineBuffer^[Line]^ );
- IPos := Position + Len;
-
- Save_Pos := POS( SearchString,
- Substr( LineBuffer^[Line]^,
- IPos ,
- L - IPos + 1 ) );
-
- IF ( Save_Pos > 0 ) THEN
- Position := Save_Pos + IPos - 1
- ELSE
- Position := 0;
-
- END
- ELSE
- BEGIN
-
- L := LENGTH( LineBuffer^[Line]^ );
- IPos := Position + S_Len;
-
- Save_Pos := POS( SearchString,
- Substr( LineBuffer^[Line]^,
- IPos ,
- L - IPos + 1 ) );
-
- IF ( Save_Pos > 0 ) THEN
- Position := Save_Pos + IPos - 1
- ELSE
- Position := 0;
-
- END;
-
- GoToXY( 1 , ScreenLine );
- ClrEol;
-
- WRITE( Substr( LineBuffer^[Line]^ , 1 , MaxECol ) );
-
- END;
-
- END;
-
- Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
- GoToXY( 1 , Max_Screen_Line );
- ClrEol;
-
- Edit_Press_Any('End of replace. Press any key to exit ...');
-
- DisplayKeys;
-
- END (* Replace *);
-
- (*----------------------------------------------------------------------*)
- (* SaveUndo --- Save current text as undo text *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE SaveUndo;
-
- BEGIN (* SaveUndo *)
- END (* SaveUndo *);
-
- (*----------------------------------------------------------------------*)
- (* Undo --- Undo current change *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Undo;
-
- BEGIN (* Undo *)
- END (* Undo *);
-
- (*----------------------------------------------------------------------*)
- (* DeleteToEOL --- Delete to end of line *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE DeleteToEOL;
-
- BEGIN (* DeleteToEOL *)
- END (* DeleteToEOL *);
-
- (*----------------------------------------------------------------------*)
- (* HandleFunc --- Execute editor function *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE HandleFunc;
-
- BEGIN (* HandleFunc *)
- (* Choose next thing to do based *)
- (* upon key entry *)
- CASE KeyNum OF
-
- 2: SaveUndo;
-
- 8: BackSpace;
-
- 9: Tab;
-
- 13: Enter;
-
- 20: DeleteToEOL;
-
- 21: Undo;
-
- 27: Esc_Key;
-
- 143: BackTab;
-
- 187: Help;
-
- 188: Locate;
-
- 189: Search;
-
- 190: Replace;
-
- 191: Terminate;
-
- 192: InsertLine;
-
- 193: DeleteLine;
-
- 196: QuitNoSave;
-
- 17,
- 199: Column := 1;
-
- 5,
- 200: CursorUp;
-
- 23,
- 201: FuncPgUp;
-
- 19,
- 203: CursorLeft;
-
- 4,
- 205: CursorRight;
-
- 18,
- 207: FuncEnd;
-
- 24,
- 208: CursorDown;
-
- 22,
- 210: Ins;
-
- 7,
- 211: Del;
-
- 26,
- 209: FuncPgDn;
-
- 1,
- 243: PrevWord;
-
- 6,
- 244: NextWord;
-
- 12,
- 246: EndFile;
-
- 17,
- 260: BeginFile;
-
- ELSE Menu_Beep;
-
- END (* Case *);
-
- END (* HandleFunc *);
-
- (*----------------------------------------------------------------------*)
- (* Dispose_Lines --- Dispose memory for text lines *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Dispose_Lines;
-
- VAR
- I: INTEGER;
-
- BEGIN (* Dispose_Lines *)
-
- FOR I := 1 TO HighestLine DO
- IF ( LineBuffer^[I] <> EmptyLine ) THEN
- DISPOSE( LineBuffer^[I] );
-
- FREEMEM( LineBuffer , SIZEOF( LinePtr ) * IntMaxLines );
-
- DISPOSE( EmptyLine );
-
- END (* Dispose_Lines *);
-
- (*----------------------------------------------------------------------*)
- (* Editor --- Begin editor main routine *)
- (*----------------------------------------------------------------------*)
-
- BEGIN (* Editor *)
- (* Initialize editor *)
-
- IF ( NOT Initialize( EditFileName ) ) THEN
- EXIT;
- (* Display screen *)
- PrintRow;
- (* Main edit loop -- get key *)
- (* and process it *)
- Edit_Done := FALSE;
-
- REPEAT
- (* Move to current position on screen *)
-
- GoToXY( Column , ScreenLine );
-
- SecNum := FALSE;
- (* Pick up character of input *)
-
- IF GetKey( SecNum , InKey ) THEN
- BEGIN
- (* If escape sequence, must be command. *)
- (* Otherwise, process as text. *)
- IF SecNum THEN
- HandleFunc
- ELSE
- Character;
- (* Update screen display *)
- PrintRow;
-
- END
- ELSE
- GiveAwayTime( 4 );
-
- UNTIL Edit_Done;
- (* Deallocate memory used for text *)
- Dispose_Lines;
-
- END (* Editor *);
-
- (*----------------------------------------------------------------------*)
- (* PibEditor --- Main program to get file name for editing *)
- (*----------------------------------------------------------------------*)
-
- BEGIN (* PibEditor *)
- (* Don't update status Line *)
-
- Save_Do_Status_Time := Do_Status_Time;
- Do_Status_Time := FALSE;
-
- (* Save screen *)
-
- Save_Partial_Screen( Saved_Screen, 5, 10, 75, 14 );
-
- Draw_Menu_Frame( 5, 10, 75, 14, Menu_Frame_Color, Menu_Title_Color,
- Menu_Text_Color, 'Edit File' );
-
- (* Get name of file to edit *)
- EditFileName := '';
-
- TextColor( Menu_Text_Color_2 );
- WRITELN('Enter name of file to edit: ');
- WRITE('>');
-
- TextColor( Menu_Text_Color );
- Read_Edited_String( EditFileName );
- WRITELN;
- (* Restore screen *)
- Restore_Screen( Saved_Screen );
- Reset_Global_Colors;
-
- (* Save screen *)
-
- IF ( EditFileName <> CHR( ESC ) ) THEN
- BEGIN
-
- Save_Screen( Saved_Screen );
- (* Edit the file *)
- Editor( EditFileName );
- (* Restore screen *)
- Restore_Screen( Saved_Screen );
- Reset_Global_Colors;
-
- END;
- (* Restore status Line check *)
-
- Do_Status_Time := Save_Do_Status_Time;
-
- END (* PibEditor *);